function tot= negtotaldonationsmult(rho, lambda1, lambda2, lambda3, b)

def=rho.*b;
n=length(rho);
z=zeros(n,1);
nozero= (rho~=0);
nz=sum(nozero);
z(nozero)=[rand(1,nz)>lambda1];
nd=sum(z);
z=(z==1);

delta=zeros(n,1);
mu=1/lambda2;
delta(z) = exprnd(mu, [nd, 1]);

mu3=1/lambda3;
alpha = exprnd(mu3, [n, 1]);

Vx= (rho.^2)/2;
Ux= Vx- delta;
U0= -alpha;
Udef= rho.* def- (def.^2)./2;

sim_donation=zeros(n,1);
sim_donation(~z)=rho(~z);
switchtorho=zeros(n,1);
switchtorho(z)= (Ux(z)>=U0(z) & Ux(z)>Udef(z));
stay_default=zeros(n,1);
stay_default(z)= (Udef(z)>=Ux(z) & Udef(z)>= U0(z));

optout=zeros(n,1);
optout(z)=(U0(z)>Ux(z) & U0(z)>Udef(z));

sim_donation(switchtorho==1)=rho(switchtorho==1);
sim_donation(stay_default==1)=def(stay_default==1);
sim_donation(optout==1)=0;

tot=-sum(sim_donation);
